package set;

import java.time.LocalDate;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

public class HashSetDemo2 {
	public static void main(String[] args) {
		HashSet set = new HashSet();
		//1.添加元素,先比较是否有相同的，有就不放，没有就放
		set.add(Boolean.valueOf(true)); 
		set.add(Integer.valueOf(123));
		set.add(Double.valueOf(1.2));
		set.add(LocalDate.now());  // 本地化日期
		set.add(null);
		
		//1.增强for
		for(Object obj : set) {
			System.out.println(obj);
		}
		System.out.println("-----------------------------");
		
		//2.使用迭代器遍历
		Iterator it = set.iterator();
		while(it.hasNext()) {
			System.out.println(it.next());
		}
		System.out.println("-----------------------------");
		
		//3.使用forEach
		set.forEach(new Consumer<Object>() {
			@Override
			public void accept(Object t) {
				System.out.println(t);
			}
		});
		System.out.println("-----------------------------");
		
		//4.forEach
		set.forEach(System.out::println);
	}
}
